package com.amigo.online.provider.adv.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.amigo.online.provider.adv.entity.AdvTantanLookRecord;
import com.amigo.online.provider.adv.mapper.AdvTantanLookRecordMapper;
import com.amigo.online.provider.adv.service.AdvTantanLookRecordService;
import com.amigo.online.provider.adv.service.AdvTantanStockService;

@Service
public class AdvTantanLookRecordServiceImpl implements AdvTantanLookRecordService {

    @Autowired
    AdvTantanLookRecordMapper advTantanLookRecordMapper;

    @Autowired
    AdvTantanStockService advTantanStockService;

    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) //事物传播机制，当前子事物不影响主事物
    public void recordTantanAdvLooked(long advId, String device, Long userId) {
        AdvTantanLookRecord record = new AdvTantanLookRecord(advId, userId, device);
        //记录数据
        advTantanLookRecordMapper.insert(record);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void recordTantanAdvLooked(long advId, String sex, Long age, Double lng, Double lat, String city) {
        AdvTantanLookRecord record = new AdvTantanLookRecord(advId, sex, age, lng, lat, city);
        advTantanLookRecordMapper.insert(record);
        advTantanStockService.deductionTantanAdvLookStock(advId);
    }

}
